package com.example.springdemo.config;/**
 * @ClassName SpringDocSwaggerConfig
 * @Description TODO
 * @author Wenyi Luo
 * @date 22/2/26 14:39
 * @version: 1.0
 */

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 @Author WenyiLuo
 @Date 22/2/26 14:39
 **/

@Configuration
public class SpringDocSwaggerConfig {

    private static final String basePackage = "com.hx.springdemo.controller";//需要扫描api路径
    private static final String headerName = "Authorization";//请求头名称


    @Bean
    public OpenAPI customOpenAPI() {
        Components components = new Components();
        //添加右上角的统一安全认证
        components.addSecuritySchemes(headerName,
                new SecurityScheme()
                        .type(SecurityScheme.Type.APIKEY)
                        .scheme("basic")
                        .name(headerName)
                        .in(SecurityScheme.In.HEADER)
                        .description("请求头"));

        return new OpenAPI().components(components).info(apiInfo());
    }

    private Info apiInfo() {
        Contact contact = new Contact();
        contact.setEmail("308631475@qq.com");
        contact.setName("gongxiaosong");
        contact.setUrl("https://blog.csdn.net/qq_42495847?spm=1000.2115.3001.5343");
        return new Info()
                .title("kmgong-swagger文档")
                .version("1.0")
                .contact(contact)
                .description("博客请关注：https://blog.csdn.net/")
                .license(new License().name("Apache 2.0")
                        .url("http://springdoc.org"));
    }
}
